package com.lyy.photovoltaic.controller;

import com.alibaba.fastjson.JSONObject;
import com.lyy.photovoltaic.beans.LeaveMessage;
import com.lyy.photovoltaic.common.vo.ResultVO;
import com.lyy.photovoltaic.service.LeaveMessageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@RequestMapping("/leaveMessage")
@Api(value = "用户留言接口", tags = "用户留言管理")
public class LeaveMessageController {
    @Autowired
    LeaveMessageService leaveMessageService;
    @PostMapping(value = "/add")
    public ResultVO addLeaveMessage(@RequestBody LeaveMessage leaveMessage) {
        ResultVO resultVO = leaveMessageService.addLeaveMessage(leaveMessage);
        return resultVO;
    }
    @GetMapping(value = "/newLeaveMessage")
    public ResultVO findNewLeaveMessage() {
        ResultVO resultVO = leaveMessageService.findNewLeaveMessage();
        return resultVO;
    }
    @GetMapping(value = "/repliedLeaveMessage/{uid}")
    @ApiImplicitParam(dataType = "string", name = "uid", value = "用户id", required = true)
    public ResultVO findRepliedLeaveMessage(@PathVariable("uid") String uId) {
        ResultVO resultVO = leaveMessageService.findRepliedLeaveMessage(uId);
        return resultVO;
    }
    @PutMapping(value = "/{lmId}")
    @ApiImplicitParam(dataType = "string", name = "lmId", value = "要回复的留言id", required = true)
    public ResultVO updateLeaveMessage(@PathVariable("lmId") String LMID,@RequestBody JSONObject jsonObject){
        return leaveMessageService.updateLeaveMessage(LMID,jsonObject);
    }
}
